package server.core;

import server.Lifecycle;
import server.LifecycleException;
import server.LifecycleListener;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandler;

public class SimpleLoader implements Lifecycle {
    private static final String WEB_ROOT = System.getProperty("user.dir") + File.separator + "webroot";
    private ClassLoader classLoader = null;
    public SimpleLoader() {
        try {
        String repository = "file:" + WEB_ROOT + File.separator;
        URL[] urls = new URL[1];
        URLStreamHandler streamHandler = null;
        urls[0] = new URL(null, repository, streamHandler);
        classLoader = new URLClassLoader(urls);
        } catch (MalformedURLException e) {
            System.out.println("servlet加载器初始化出错");
            e.printStackTrace();
        }
    }
    public ClassLoader getClassLoader() {
        return this.classLoader;
    }
    public String getInfo() {
        return "A simple loader";
    }

    @Override
    public void addLifecycleListener(LifecycleListener listener) {

    }

    @Override
    public LifecycleListener[] findLifecycleListeners() {
        return null;
    }

    @Override
    public void removeLifecycleListener(LifecycleListener listener) {

    }

    @Override
    public void start() throws LifecycleException {
        System.out.println("Starting SimpleLoader");
    }

    @Override
    public void stop() throws LifecycleException {

    }

    //实现Lifecycle接口-------------------------------------------------------------------------

}

